package com.joinval.modules.sys.controller;

import com.joinval.common.utils.Result;
import com.joinval.modules.sys.entity.SysUserAuditLog;
import com.joinval.modules.sys.enums.UserTypeEnums;
import com.joinval.modules.sys.form.SysUserAuditLogForm;
import com.joinval.modules.sys.service.SysUserAuditLogService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


/**
 * 用户审核记录
 *
 * @author xu
 * @email -
 * @date 2020-08-25 10:32:42
 */
@Api(description = "用户审核记录")
@RestController
@RequestMapping("sys/sysUserAuditLog")
public class SysUserAuditLogController {

    @Autowired
    private SysUserAuditLogService sysUserAuditLogService;

    /**
     * 审核
     * @return
     */
    @ApiOperation(value = "审核(type{1:志愿者,2:点单机构})")
    @PostMapping(value = "/audit/{type}")
    public Result audit(@PathVariable String type,@RequestBody SysUserAuditLogForm form) {
        return sysUserAuditLogService.audit(UserTypeEnums.getEnum(type),form);
    }


    /**
     * 信息
     */
    @ApiOperation(value="信息")
    @GetMapping("/info/{sysUserAuditLogId}")
    public Result info(@PathVariable("sysUserAuditLogId") Long sysUserAuditLogId){
		SysUserAuditLog sysUserAuditLog = sysUserAuditLogService.getById(sysUserAuditLogId);
        return Result.ok().data(sysUserAuditLog);
    }

    /**
     * 新增
     */
    @ApiOperation(value="新增")
    @PostMapping("/save")
    public Result save(@RequestBody SysUserAuditLog sysUserAuditLog){
        Boolean result = sysUserAuditLogService.save(sysUserAuditLog);
        return result?Result.ok():Result.error("保存失败");
    }

    /**
     * 修改
     */
    @ApiOperation(value="修改")
    @PostMapping("/update")
    public Result update(@RequestBody SysUserAuditLog sysUserAuditLog){
        Boolean result = sysUserAuditLogService.updateById(sysUserAuditLog);
        return result?Result.ok():Result.error("更新失败");
    }

    /**
     * 删除
     */
    @ApiOperation(value="删除")
    @PostMapping("/delete/{sysUserAuditLog}")
    public Result delete(@PathVariable("sysUserAuditLog") Long sysUserAuditLog){
		Boolean result = sysUserAuditLogService.removeById(sysUserAuditLog);
        return result?Result.ok():Result.error("删除失败");
    }

}
